Integrate Sendinblue Transactional Email in C#
Sendinblue API can be used by platforms developed in various languages like PHP, Java, Node.js, Python, C#, and Ruby.
Integrating send in blue to your site C#
Before Starting If you want to know how to set up the send in the blue dashboard before integration click the link to know more: How to Integrate Sendinblue Transactional Email
First Download the library from Send in blue GitHub
To add the library to your Project file is after download creates a new folder in your project and add mailinblue.dll which is present in this folder -> \V2.0\mailinblue\bin\mailinblue.dll.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mailinblue;
namespace SendinblueTest {
public partial class index : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
API sendinBlue = new mailinblue.API("add you api key");
//add your api key here Dictionary
<string, Object> data = new Dictionary<string, Object>();
Dictionary<string, string> to = new Dictionary<string, string>();
to.Add("to@email.com", "to whom!");
List<string> from_name = new List<string>();
from_name.Add("from@email.com");
from_name.Add("from email!");
List<string> attachment = new List<string>();
attachment.Add("https://domain.com/path-to-file/filename1.pdf");
attachment.Add("https://domain.com/path-to-file/filename2.jpg");
data.Add("to", to);
data.Add("from", from_name);
data.Add("subject", "My subject");
data.Add("html", "This is the <h1>HTML</h1>");
data.Add("attachment", attachment);
Object sendEmail = sendinBlue.send_email(data);
response.InnerHtml = sendEmail.ToString();
}
}
}
To send attachment/s generated on the fly.
Please note that your email content and attached files size should not be greater than 10 MB.
/* To send attachment/s generated on the fly you have to pass your attachment/s filename & its base64 encoded chunk data in key-value pair in attachment input. Prepare your attachment input as mentioned below. Dictionary<string, string> attachment = new Dictionary<string, string>(); attachment.Add("YourFileName1.Extension", "Base64EncodedChunkData1"); attachment.Add("YourFileName2.Extension", "Base64EncodedChunkData2"); This will send an email with attachment/s from your SendinBlue account. */
using System;
using System.Collections.Generic;
using mailinblue;
namespace SendinblueTest {
class Program {
static void Main(string[] args) {
API sendinBlue = new mailinblue.API("your access key");
Dictionary < string, Object > data = new Dictionary < string, Object > ();
Dictionary < string, string > to = new Dictionary < string, string > ();
to.Add("to@example.net", "to whom!");
List < string > from_name = new List < string > ();
from_name.Add("from@email.com");
from_name.Add("from email!");
Dictionary < string, string > cc = new Dictionary < string, string > ();
cc.Add("cc@example.net", "cc whom!");
Dictionary < string, string > bcc = new Dictionary < string, string > ();
bcc.Add("bcc@example.net", "bcc whom!");
List < string > replyto = new List < string > ();
replyto.Add("replyto@email.com");
replyto.Add("reply to!");
Dictionary < string, string > attachment = new Dictionary < string, string > ();
attachment.Add("myfilename.pdf", "your_pdf_files_base64_encoded_chunk_data");
Dictionary < string, string > inline_image = new Dictionary < string, string > ();
inline_image.Add("myinlineimage1.png", "your_png_files_base64_encoded_chunk_data");
inline_image.Add("myinlineimage2.jpg", "your_jpg_files_base64_encoded_chunk_data");
Dictionary < string, string > headers = new Dictionary < string, string > ();
headers.Add("Content-Type", "text/html; charset=iso-8859-1");
headers.Add("X-param1", "value1");
headers.Add("X-param2", "value2");
headers.Add("X-Mailin-custom", "my custom value");
headers.Add("X-Mailin-IP", "102.102.1.2");
headers.Add("X-Mailin-Tag", "My tag");
data.Add("to", to);
data.Add("cc", cc);
data.Add("bcc", bcc);
data.Add("replyto", replyto);
data.Add("from", from_name);
data.Add("subject", "My subject");
data.Add("html", "This is the <h1>HTML</h1><br/> This is inline image 1.<br/> <img src=\"{myinlineimage1.png}\" alt=\"image1\" border=\"0\"><br/> Some text<br/> This is inline image 2.<br/> <img src=\"{myinlineimage2.jpg}\" alt=\"image2\" border=\"0\"><br/> Some more text<br/> Re-used inline image 1.<br/> <img src=\"{myinlineimage1.png}\" alt=\"image3\" border=\"0\">");
data.Add("text", "This is text");
data.Add("attachment", attachment);
data.Add("headers", headers);
data.Add("inline_image", inline_image);
Object sendEmail = sendinBlue.send_email(data);
Console.WriteLine(sendEmail);
}
}
}
Arjun is a Full-stack developer, who is fond of the web. Lives in Chikmagalur, Karnataka, India